package com.sgb.kjwl.viewmodel.self.pick;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.user.OfferEntity;
import com.sgb.kjwl.model.entity.user.UserLaborEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.fragment.self.pick.UserLaborFragment;
import com.sgb.kjwl.view.ui.fragment.self.pick.UserOfferFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UserOfferFragModel extends BaseViewModel {
    private SelfRepertory repertory;
    private UserOfferFragment fragment;
    private int page = 1;
    private int size = 10;
    public int total;

    public UserOfferFragModel(UserOfferFragment fragment, SelfRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
    }

    public void getData(String no){
        page =1;
        APIManager.getInstance().getPickAPI().getBiddingListByTenderNo(page, size, no).enqueue(new Callback<BaseEntity<ProListEntity<List<OfferEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ProListEntity<List<OfferEntity>>>> call, Response<BaseEntity<ProListEntity<List<OfferEntity>>>> response) {
                if (response.body() == null || response.body().getState()==null){
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)){
                    total = response.body().getData().getTotalRow();
                    fragment.showData(response.body().getData().getList());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ProListEntity<List<OfferEntity>>>> call, Throwable t) {

            }
        });
    }

    public void getMoreData(String no){
        page++;
        APIManager.getInstance().getPickAPI().getBiddingListByTenderNo(page, size, no).enqueue(new Callback<BaseEntity<ProListEntity<List<OfferEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ProListEntity<List<OfferEntity>>>> call, Response<BaseEntity<ProListEntity<List<OfferEntity>>>> response) {
                if (response.body() == null || response.body().getState()==null){
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)){
                    fragment.showMoreData(response.body().getData().getList());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ProListEntity<List<OfferEntity>>>> call, Throwable t) {

            }
        });
    }
}
